<?php


class Module extends Object
{
    var $_Error;
    var $_Modules;

    function __construct()
    {
        Vault::Add('Module', &$this);

        $this->_Error = &Vault::Get('Debug_Error');
    }

    function &Get($application, $extension)
    {    
        if (isset($this->_Modules[$application][$extension]))
            return $this->_Modules[$application][$extension];
        else
        {            
            if (file_exists(W_ENV_PATH.'/Extensions/'.$application.'/'.$extension.'/module.php'))
            {
                using('Extensions.'.$application.'.'.$extension.'.module');

                if (class_exists(($class = 'Module_'.$application.'_'.$extension)))
                {
                    $this->_Error->Log('Module :: Initialising \''.$class.'\'', W_LOG_DEBUG);
                    $this->_Modules[$application][$extension] = new $class();

                    return $this->_Modules[$application][$extension];
                }
                else
                {
                    $trace = debug_backtrace();
                    $this->_Error->Log('Module :: Error Loading \''.$class.'\' requested by \''.str_replace(W_ENV_PATH, '', $trace[1]['file']).':'.$trace[1]['line'].'\'', W_LOG_CRIT);
                }
            }
            else
                return false;
        }
    }
}

?>